package com.vitabuybuy.tv.network

import com.library.common.net.NetUrl
import com.vitabuybuy.tv.dto.OrderDetailDto
import com.vitabuybuy.tv.dto.OrderListDto
import rxhttp.IAwait
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

/**
 * 作者：SimGa
 * 日期：2020/12/16
 * 时间：10:58
 * 包名：com.vitabuybuy.tv.network
 */
object OrderRepository {

    fun getOrderList(
        status: String?,
        keyWord: String,
        pageNumber: Int,
        pageSize: Int
    ): IAwait<MutableList<OrderListDto>> {
        val params = HashMap<String, Any?>()
        params["pageable"] = mapOf(
            Pair("page", pageNumber),
            Pair("size", pageSize),
            Pair("desc", "id")
        )
        if (keyWord.isNotEmpty()) {
            params["keyword"] = keyWord
        }
        if (!status.isNullOrEmpty()) {
            params["status"] = status
        }
        return RxHttp.postJson(NetUrl.api_find_allorder).addAll(params).toResponse()
    }

    fun cancelOrder(
        id: Int?
    ): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_cancel_order).add("id", id).toResponse()

    }

    fun receiverOrder(
        id: Int?
    ): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_sign_order).add("id", id).toResponse()

    }

    fun deleteOrder(
        id: Int?
    ): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_delete_order).add("id", id).toResponse()

    }

    fun remindOrder(
        id: Int?
    ): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_remind_send).add("id", id).toResponse()

    }

    fun getOrderDetail(
        id: Int?
    ): IAwait<OrderDetailDto> {
        return RxHttp.postJson(NetUrl.api_order_findByIdWithMe)
            .add("id", id).toResponse()
    }

    fun saveEvaluation(
        params: HashMap<String, Any>
    ): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_my_save_comment).addAll(params).toResponse()
    }
}